package vo;

import java.io.Serializable;
import po.*;
import exception.ExpenseNotEnoughException;
import java.util.Calendar;

public class GiftVO implements Serializable {
	private static final long serialVersionUID = 1276762873441734060L;
	GiftPO giftPO;

	public GiftVO() {
		super();
		giftPO = new GiftPO();
	}

	public GiftVO(GiftPO giftpo) {
		this.giftPO = giftpo;
	}

	public String toString() {
		return this.giftPO.toString();
	}

	public GiftPO getGiftPO() {
		return giftPO;
	}

	public int getID() {
		return this.giftPO.getId();
	}

	public Calendar getBeginDate() {
		return this.giftPO.getBeginDate();
	}

	public Calendar getEndDate() {
		return this.giftPO.getEndDate();
	}

	public GiftType getType() {
		return this.giftPO.getType();
	}

	public boolean isValid() {
		return this.giftPO.isValid();
	}

	public double getPrice(double expense) throws ExpenseNotEnoughException {
		if ((this.giftPO.getType() == GiftType.EQUIVALENCE)) {
			if (((Equivalence) this.giftPO).getRequiredPay() > expense)
				throw new ExpenseNotEnoughException(expense);
			else
				return expense - ((Equivalence) this.giftPO).getValue();
		} else
			return expense * ((Discount) this.giftPO).getRate();
	}
	
	public String getDescription() {
		if (giftPO instanceof Equivalence) {
			return ((Equivalence) giftPO).getDescription();
		}
		else {
			return ((Discount) giftPO).getDescription();
		}
	}
	
	public String getShortDescription() {
		if (giftPO instanceof Equivalence) {
			return ((Equivalence) giftPO).getShortDescription();
		}
		else {
			return ((Discount) giftPO).getShortDescription();
		}
	}
}
